home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / libraries / curses210.lha / src / _creatwin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-22  |  4.4 KB  |  146 lines

  1. /* -*-C-*-
  2.  *
  3.  *
  4.  * Filename : _creatwin.c
  5.  *
  6.  * Author   : Simon J Raybould.    (sie@fulcrum.bt.co.uk).
  7.  *
  8.  * Date     : Friday 23rd August 1991.
  9.  *
  10.  * Desc     : Creats a new window, which may or may not be a sub window.
  11.  *
  12.  *
  13.  * THIS CODE IS NOT PUBLIC DOMAIN
  14.  * ==============================
  15.  * 
  16.  * This code is copyright Simon J Raybould 1991, all rights are reserved.
  17.  * All code, ideas, data structures and algorithms remain the property of the
  18.  * author. Neither the whole nor sections of this code may be used as part
  19.  * of other code without the authors consent. If you wish to use some of this
  20.  * code then please email me at (sie@fulcrum.bt.co.uk).
  21.  *
  22.  * This source is not public domain, so you do not have any right to alter it
  23.  * or sell it for personal gain. The source is provided purely for reference
  24.  * purposes. You may re-compile the source with any compiler you choose.
  25.  * You must not distribute altered copies without the authors consent. My
  26.  * intention is that the source will help people isolate any bugs much more
  27.  * effectivly.
  28.  *
  29.  * Disclaimer
  30.  * ==========
  31.  *
  32.  * No implication is made as to this code being fit for any purpose at all.
  33.  * I (the author) shall not be held responsible for any loss of data or damage 
  34.  * to property that may result from its use or misuse.
  35.  *
  36.  *
  37.  * Revision History
  38.  * ================
  39.  *
  40.  * $Log: _creatwin.c,v $
  41.  * Revision 1.7  1993/05/17  23:31:21  sie
  42.  * Underscores added to names.
  43.  *
  44.  * Revision 1.6  1992/06/10  23:45:07  sie
  45.  * Added serial support.
  46.  *
  47.  * Revision 1.5  91/12/30  10:30:22  sie
  48.  * Removed LRLine and LRATTRS.
  49.  * The speed increase caused by them was too insignificant.
  50.  * 
  51.  * Revision 1.4  91/12/28  22:46:13  sie
  52.  * changed attrs to UBYTE from short + some tidying up.
  53.  * 
  54.  * Revision 1.3  91/12/28  14:01:54  sie
  55.  * Removed WinStat.
  56.  * Renamed LineElement as lnel.
  57.  * 
  58.  * Revision 1.2  91/12/26  14:40:31  sie
  59.  * removed use of Next and Prev in WinStat as linked list is no longer
  60.  * relevant.
  61.  * 
  62.  * Revision 1.1  91/09/07  11:52:46  sie
  63.  * Initial revision
  64.  * 
  65.  *
  66.  */
  67.  
  68. static char *rcsid = "$Header: /SRC/lib/curses/src/RCS/_creatwin.c,v 1.7 1993/05/17 23:31:21 sie Exp $";
  69.  
  70. #include <stdlib.h>
  71. #include "acurses.h"
  72.  
  73.  
  74. /* Orig is NULL and StartCol/Line are not used for newwin() calls */
  75. WINDOW *_CreatWindow(int NLines, int NCols, int StartLine, int StartCol, WINDOW *Orig)
  76. {
  77.   int Line;
  78.   WINDOW *NewWinPtr;
  79.   
  80.   /* If either are zero then make them max */
  81.   if(!NLines)
  82.     NLines = LINES - StartLine;
  83.   if(!NCols)
  84.     NCols = COLS - StartCol;
  85.   
  86.   if(NLines>LINES || NCols>COLS || StartLine>LINES || StartCol>COLS)
  87.     return NULL;
  88.   
  89.   if(StartLine < 0)
  90.     StartLine = 0;
  91.   if(StartCol < 0)
  92.     StartCol = 0;
  93.   
  94.   /* Create a new WINDOW structure */
  95.   if(!(NewWinPtr=(WINDOW *)malloc(sizeof(WINDOW)))) {
  96.     fprintf(stderr, "CreatWindow() - Not enough memory\n");
  97.     return NULL;
  98.   }
  99.   NewWinPtr->ParentWin = Orig;
  100.   NewWinPtr->ScrollTop = 0;
  101.   NewWinPtr->ScrollBot = NLines - 1;
  102.   NewWinPtr->NLines = NLines;
  103.   /* Allocate space for LnArry[] */
  104.   if(!(NewWinPtr->LnArry = (struct lnel *)malloc(sizeof(struct lnel)*NLines))) {
  105.     fprintf(stderr, "CreatWindow() - Not enough memory\n");
  106.     return NULL;
  107.   }
  108.   /* Allocate space for Line and ATTRS */
  109.   for(Line = 0; Line < NLines; Line++) {
  110.     if(Orig) {  /* If this is a subwindow */
  111.       /* Set up pointers into parent window */
  112.       NewWinPtr->LnArry[Line].Line =
  113.     &Orig->LnArry[Line+StartLine].Line[StartCol];
  114.       NewWinPtr->LnArry[Line].ATTRS =
  115.     &Orig->LnArry[Line+StartLine].ATTRS[StartCol];
  116.     } else {  /* New window, allocate space for lines */
  117.       /* malloc lines and ATTRS */
  118.       if((NewWinPtr->LnArry[Line].Line = malloc(NCols)) == NULL) {
  119.     fprintf(stderr, "CreatWindow() - Not enough memory\n");
  120.     return (WINDOW *)NULL;
  121.       }
  122.       if((NewWinPtr->LnArry[Line].ATTRS = (UBYTE *)malloc(NCols)) == NULL) {
  123.     fprintf(stderr, "CreatWindow() - Not enough memory\n");
  124.     return (WINDOW *)NULL;
  125.       }
  126.     }
  127.     NewWinPtr->LnArry[Line].Touched = FALSE;
  128.     NewWinPtr->LnArry[Line].StartCol = NCols;
  129.     NewWinPtr->LnArry[Line].EndCol = 0;
  130.   }
  131.   /* Initialise rest of the window structure */
  132.   NewWinPtr->_cury = 0;
  133.   NewWinPtr->_curx = 0;
  134.   NewWinPtr->_maxy = NLines - 1;
  135.   NewWinPtr->_maxx = NCols - 1;
  136.   NewWinPtr->_begy = StartLine;
  137.   NewWinPtr->_begx = StartCol;
  138.   NewWinPtr->_flags = 0;
  139.   NewWinPtr->_attrs = A_NORMAL | COLOR_WHITE;
  140.   NewWinPtr->_clear = FALSE;
  141.   NewWinPtr->_scroll = FALSE;
  142.   NewWinPtr->_nodelay = 0;
  143.   
  144.   return NewWinPtr;
  145. }
  146.